package com.third.device.mg.serialport.factory.forick

import kotlin.experimental.and

/**
 * @Date 2022/4/18
 * Description:弗雷克 三选一环境面板 参数
 */
object VendorFLKFromPl {
    const val VENDOROP_TC = 0x7fb0.toShort() //tc=temperature control

    const val TC_STATUS_GET = 0x00.toByte()
    const val TC_STATUS_RET = 0x01.toByte()
    const val TC_SET = 0x02.toByte()
    const val TC_SET_RESULT = 0x03.toByte()

    const val TC_GET_NOTIFY = 0x04.toByte()
    const val TC_SET_NOTIFY = 0x05.toByte()
    const val TC_RET_NOTIFY = 0x06.toByte()

    const val TYPE_WORK_MODE = 0x00.toByte()

    const val TYPE_AC_ONOFF = 0x01.toByte()
    const val TYPE_AC_MODE = 0x02.toByte()
    const val TYPE_AC_SPEED = 0x03.toByte()
    const val TYPE_AC_TEMPERATURE = 0x04.toByte()
    const val TYPE_AC_VALVE = 0x05.toByte()
    const val TYPE_AC_RELAY = 0x06.toByte()

    const val TYPE_FH_ONOFF = 0x07.toByte()
    const val TYPE_FH_TEMPERATURE = 0x08.toByte()
    const val TYPE_FH_VALVE = 0x09.toByte()
    const val TYPE_FH_RELAY = 0x0A.toByte()
    const val TYPE_FH_PROTECT_TEMP = 0x0B.toByte()

    const val TYPE_FA_ONOFF = 0x0C.toByte()
    const val TYPE_FA_SPEED = 0x0D.toByte()
    const val TYPE_FA_RELAY = 0x0E.toByte()

    const val TYPE_COMP_TEMP = 0x0F.toByte()
    const val TYPE_ENV_TEMP = 0x10.toByte()
    const val TYPE_ENV_HUMIDITY = 0x11.toByte()

    const val TYPE_LOW_TEMP = 0x12.toByte()

    const val TYPE_BG_DURATION = 0x13.toByte()
    const val TYPE_BG_LIGHTNESS = 0x14.toByte()
    //**************************三选一环境面板 参数************************************************************

    /*
    *
    *
    * public static short byte2shortBE(byte[] input, int offset){
        return (short)((input[0 + offset] & 0xff) << 8 | input[1 + offset] & 0xff);
    }

    public static void short2byteBE(short input, byte[]output, int offset){
        output[1 + offset] = (byte)(input);
        output[0 + offset] = (byte)((input)>>8);
    }
    *
    * */
    fun byte2shortBE(input: ByteArray, offset: Int): Short {
        val data = byteArrayOf(input[offset + 1] ,input[offset])
        return (((data[1].toInt() and 0xFF) shl 8) or (data[0].toInt() and 0xFF)).toShort()
    }

    fun short2byteBE(input: Short, output: ByteArray, offset: Int) {
        output[0 + offset] = (input.toInt() shr 8).toByte()
        output[1 + offset] = (input and 0xff).toByte()
    }
}